package com.motherchild.admin.controller;

import com.motherchild.admin.dto.CategoryDTO;
import com.motherchild.admin.service.CategoryService;
import com.motherchild.admin.vo.CategoryVO;
import com.motherchild.common.ApiResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/categories")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/getList")
    public ApiResponse<List<CategoryVO>> getList() {
        return ApiResponse.success(categoryService.getList());
    }

    @GetMapping("/getCategoryDetail/{id}")
    public ApiResponse<CategoryVO> getDetail(@PathVariable Long id) {
        return ApiResponse.success(categoryService.getDetail(id));



    }

    @PostMapping("/add")
    public ApiResponse<?> add(@RequestBody CategoryDTO categoryDTO) {
        try {
            categoryService.add(categoryDTO);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e);
        }
        return ApiResponse.success();
    }

    @PutMapping("/update/{id}")
    public ApiResponse<?> update(@PathVariable Long id, @RequestBody CategoryDTO categoryDTO) {
        categoryService.update(id, categoryDTO);
        return ApiResponse.success();
    }

    @DeleteMapping("/delete/{id}")
    public ApiResponse<?> delete(@PathVariable Long id) {
        categoryService.delete(id);
        return ApiResponse.success();
    }

    @PutMapping("/status/{id}")
    public ApiResponse<?> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
        categoryService.updateStatus(id, status);
        return ApiResponse.success();
    }
} 